using System.Collections.Generic;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using EnvDTE80;

namespace TeamReview.Replay
{
	internal class ReplayChain : ReplayLink
	{
		private IList<ReplayLink> _chain = new List<ReplayLink>();

		public IList<ReplayLink> Chain
		{
			get { return _chain; }
		}

        public ReplayChain(DTE2 applicationObject) : base(applicationObject)
        {
            _chain.Add(new LineNumbersLink(applicationObject));
            _chain.Add(new CodeElementFirstSnippetLink(applicationObject,Constants.CODE_MEMBER_FIELD, "Code Member"));
            _chain.Add(new CodeElementFirstSnippetLink(applicationObject,Constants.CODE_CLASS_FIELD, "Code Class"));
            _chain.Add(new CodeElementLink(applicationObject,Constants.CODE_MEMBER_FIELD, "Code Member"));
            _chain.Add(new CodeElementLink(applicationObject,Constants.CODE_CLASS_FIELD, "Code Class"));
            _chain.Add(new FirstSnippetInDocumentLink(applicationObject));
            _chain.Add(new ItemNotFoundLink(applicationObject));
        }


        public override ReplayReceipt TryShowReplay(WorkItem workItem, DTE2 applicationObject)
		{
			ReplayReceipt receipt = new ReplayReceipt();
			for (int i = 0; i < _chain.Count && receipt.ItemWasFound == false; i++)
				receipt = Chain[i].TryShowReplay(workItem, applicationObject);

			return receipt;
		}
	}
}
